<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Node extends Base
{
    //修改器 route_name
    public function setRouteNameAttribute($value)
    {
        $this->attributes['route_name']=empty($value)?'':$value;
    }
    //访问器
    public function getMenuAttribute()
    {
      /*  if($this->is_menu=='1'){
            return "<span class='label label-success radius'>是</span>";
        }else{
            return "<span class='label label-warning radius'>否</span>";
        }*/
        return $this->is_menu == "1"?'<span class="label label-success radius">是</span>':'<span class="label label-warning radius">否</span>';
    }
    //获取全部数据
    public function getAllList()
    {
        $data = self::get()->toArray();
        return $this->treeLevel($data);
    }
    //获得有层级的数据
    //用户有的权限
    public function treeData($allow_node)
    {
        $query = Node::where('is_menu','1');
        if(is_array($allow_node)){
            $query->whereIn('id',array_keys($allow_node));
        }
        $menuData = $query->get()->toArray();
        return $this->subTree($menuData);
    }
}
